package component.global.utils
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Loader;

	public class DisplayUtils
	{
		/**
		 * 从舞台移除显示对象
		 * @param args
		 * 
		 */		
		public static function removeDisplay(...args):void{
			for (var i:int = 0; i < args.length; i++) 
			{
				if(args[i] && args[i].parent){
					if(!(args[i].parent is Loader)){
						args[i].parent.removeChild(args[i]);
					}
				}
			}
		}
		
		/**
		 * 移动对象到点(px,py)处
		 * @param display
		 * @param px
		 * @param py
		 * @return 
		 * 
		 */		
		public static function move(display:DisplayObject, px:int, py:int):void{
			if(display == null)return;
			display.x = px;
			display.y = py;
		}
		
		public static function addDisplayObject(container:DisplayObjectContainer, ...args):DisplayObjectContainer{
			if(container == null)return container;
			while(args.length > 0){
				container.addChild(args.shift());
			}
			return container;
		}
		
		public static function addDisplayObjectAt(container:DisplayObjectContainer,idx:int, ...args):DisplayObjectContainer{
			if(container == null)return container;
			while(args.length > 0){
				container.addChildAt(args.shift(),idx);
			}
			return container;
		}
		
		public static function removeAllChildren(container:DisplayObjectContainer):void{
			while(container.numChildren > 0){
				container.removeChildAt(0);
			}
		}
	}
}